<?php use_stylesheet('bdelag_fullcalendar.css') ?>
<?php use_stylesheet('bdelag_theme.css') ?>

<?php use_javascript('bdelag_fullcalendar.js') ?>
<?php use_javascript('jquery-ui.js') ?>
<?php use_javascript('ui.core.js') ?>
<?php use_javascript('ui.draggable.js') ?>
<?php use_javascript('ui.resizable.js') ?>



<script type='text/javascript'>

	$(document).ready(function() {

		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();

		$('#calendar').fullCalendar({
			theme: true,
			firstDay: 1,
			firstHour: 7,
			allDayDefault: false,
			header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
			},
			selectable: {
				month: true,
				agenda: true,
                                week: true
			},
			editable: true,
                        disableResizing : false,

                         select: function( startDate, endDate, allDay, jsEvent, view ){

                             var jd = startDate.getDate();
                             var md = startDate.getMonth()+1;
                             var yd = startDate.getFullYear();

                             var jf = endDate.getDate();
                             var mf = endDate.getMonth()+1;
                             var yf = endDate.getFullYear();

                             var paramdebut = '?jd='+jd+'&md='+md+'&yd='+yd;
                             var paramfin = '&jf='+jf+'&mf='+mf+'&yf='+yf;

                             var link = '<?php echo url_for('events/new') ?>'+paramdebut+paramfin ;
                             var answer = confirm ("Ajouter un évènement sur la plage selectionné ?");

                             if (answer)
                                document.location.href=link ;


                         },

                         eventResize:function( event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view ) {

                            var EndDate = event.end;
                            var HeureEndDate = EndDate.getHours();
                            var MinuteEndDate = EndDate.getMinutes();
                            var HeureDeFin = HeureEndDate+":"+MinuteEndDate;

                            if (confirm("Mettre à jour les horraires de : "+event.title + " ? \n\Finir désormais à : " + HeureEndDate +" heure(s) et "+ MinuteEndDate + " minute(s)"))
                            {
                                var link = '<?php echo url_for('events/edit') ?>'+'?idevent='+event.id+'&HDF='+HeureDeFin;
                                document.location.href=link ;
                            }


                         },

                         eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {

                                var nbrdaymoved = dayDelta;

                                if (confirm(event.title + " a été déplacer de " +
                                    dayDelta+" jour(s)"))
                                {
                                    var link = '<?php echo url_for('events/edit') ?>'+'?idevent='+event.id+'&nbrdaymoved='+nbrdaymoved;
                                    document.location.href=link ;
                                }
                            },

			events: [
			<?php $total = count($events); $i=0; ?>
			<?php foreach ($events as $event): ?>
                        <?php $i++; ?>
			{
				id: '<?php echo $event->getId() ?>',
				title: '<?php echo $event->getTitle() ?>',
				start: '<?php echo $event->getStartDate()." ".$event->getStartHours() ?>',
				end: '<?php echo $event->getEndDate()." ".$event->getEndHours() ?>',
				url: '<?php echo url_for('events/show?id='.$event->getId()) ?>'
			}<?php if ($i != $total) echo "," ?>
			<?php endforeach; ?>
			]
		});
	});
</script>

<style type='text/css'>

	body {
		margin-top: 40px;
		text-align: center;
		font-size: 13px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
		}

	#calendar {
		width: 100%;
		margin: 0 auto;
		}
</style>

<a href="<?php echo url_for('events/new') ?>"></a>

<div id='calendar'></div>


